//
//  BEAccountInfoVc.swift
//  BEGlobalOiler
//
//  Created by KKING on 2016/10/13.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit

class BEAccountInfoVc: UIViewController {
    
    @IBOutlet weak var iconImgView: UIImageView!
    @IBOutlet weak var nameTf: UILabel!
    
    @IBOutlet weak var fullNameTf: UILabel!
    @IBOutlet weak var userIdTf: UILabel!
    @IBOutlet weak var phoneNumberTf: UILabel!
    @IBOutlet weak var emailTf: UILabel!
    
    @IBOutlet weak var companyTf: UILabel!
    @IBOutlet weak var addressTf: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        companyTf.text = BEAccountModel.shareAccount()?.companyName

        loadData()
    }
    
    private func loadData(){
        BENetworkTools.shareNetworkTool.loadAccountInfo { (success, result, error) in
            guard let resultjson = result else {
                //                JFProgressHUD.showWithStatus(status: "Network fault!")
                return
            }
            if resultjson["success"] == true {
                guard let dict = resultjson["result"].dictionaryObject else{
                    return
                }
                DispatchQueue.main.async(execute: {
                    self.fullNameTf.text = dict["fullName"] as! String?
                    self.nameTf.text = dict["fullName"] as! String?
                    self.userIdTf.text = dict["userId"] as! String?
                    self.phoneNumberTf.text = dict["mobile"] as! String?
                    self.emailTf.text = dict["email"] as! String?
                    
                    self.addressTf.text = dict["address"] as! String?
                    
                    guard let urlString = dict["photo"] else {
                        return
                    }
                    let url = URL(string: urlString as! String)
                    self.iconImgView.kf.setImage(with: url, placeholder: #imageLiteral(resourceName: "avatar_default_big"), options: [], progressBlock: nil, completionHandler: nil)
                })
                //                JFProgressHUD.showSuccessWithStatus(status: "Data loading successfully!")
            } else {
                //                JFProgressHUD.showInfoWithStatus(status: resultjson["message"].stringValue)
            }
        }
    }
}
